package com.softme.trade.system;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.softme.trade.engine.setup.SetupEngine;

public class StartupServlet extends HttpServlet
{
	private static final long serialVersionUID = 1L;

	private static final Log log = LogFactory.getLog(StartupServlet.class);

	@Override
	public void init(ServletConfig config) throws ServletException
	{
		super.init(config);
		
		if (StartupServlet.log.isDebugEnabled())
			StartupServlet.log.debug("Initializing startup servlet...");

		StartupServlet.log.warn(getServletContext().getRealPath("/"));

		try
		{
			//faz p setup do sistema
			SetupEngine.getInstance().run();
		}
		catch (Throwable e)
		{
			log.fatal("Error initializing startup servlet", e);
			throw new ServletException(e);
		}
	}

	public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
	{

	}

	@Override
	public void destroy()
	{
		super.destroy();
		if (StartupServlet.log.isDebugEnabled())
			StartupServlet.log.debug("Destroying startup servlet...");
	}

	@Override
	protected void finalize() throws Throwable
	{
		super.finalize();
		if (StartupServlet.log.isDebugEnabled())
			StartupServlet.log.debug("Finalizing startup servlet...");
	}
}
